<?php

namespace App\Biz;

use App\Events\VisitorApprovalEvent;
use App\Models\IntervieweeInformation;
use Exception;
use Psr\SimpleCache\InvalidArgumentException;

class IntervieweeReservesBiz extends BaseBiz
{
    public function __construct(IntervieweeInformation $intervieweeInformation)
    {
        $this->model     = $intervieweeInformation;
    }

    /**
     * 获取所有访客预约并且审核
     * @return void
     * @throws InvalidArgumentException
     * @throws Exception
     */
    public function visitorReservesListApproval(): void
    {
        //获取所有受访者信息
        $intervieweeInformationLists = $this->model->get();
        if ($intervieweeInformationLists->isNotEmpty()) {
            foreach ($intervieweeInformationLists as $intervieweeInformation) {
                //IntervieweeBiz 对象
                $intervieweeBiz = $intervieweeInformation->intervieweeBiz();
                //访客列表
                $visitorReservesList = $intervieweeBiz->visitorReservesList();

                if ($visitorReservesList->isNotEmpty()) {
                    //访客预约审核
                    $visitorReservesApproval = $intervieweeBiz->visitorReservesApproval($visitorReservesList->implode('uniqueId', ','));

                    $visitorReservesApproval !== false && event(new VisitorApprovalEvent($visitorReservesList));
                }
            }
        }
    }
}
